<#import "/layout/mainLayout.html" as mainLayout />

<#macro mainheading>
    <link rel="stylesheet" href="/plugins/datatables/dataTables.bootstrap.css">

</#macro>
<#assign mainheading = mainheading in mainLayout />

<#macro maincontent>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <div class="row">
                            <div class="col-sm-2">
                                <select class="form-control" id="input_state">
                                    <option value="-1">--用户状态--</option>
                                    <option value="0">正常</option>
                                    <option value="1">锁定</option>
                                    <option value="2">禁言</option>
                                </select>
                            </div>
                            <div class="col-sm-2">
                                <select class="form-control" id="input_regstate">
                                    <option value="-1">--注册类型--</option>
                                    <option value="1">后台注册</option>
                                    <option value="2">Web注册</option>
                                    <option value="3">Client注册</option>
                                    <option value="4">Android注册</option>
                                    <option value="5">IOS注册</option>
                                </select>
                            </div>
                            <div class="col-sm-2">
                                <select class="form-control" id="input_isvip">
                                    <option value="-1">--充值状态--</option>
                                    <option value="1">会员</option>
                                    <option value="2">非会员</option>
                                </select>
                            </div>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="input_nick" placeholder="昵称...">
                            </div>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="input_phone" placeholder="电话...">
                            </div>

                            <div class="col-sm-1 pull-right">
                                <button class="btn btn-block btn-default " id ="btn_search" onclick="searchStudents()">查询
                                </button>
                            </div>
                        </div><!-- /.box-header -->
                    </div>

                    <div class="box-body table-responsive no-padding">
                        <table id="usertable" class="table table-bordered table-striped dataTable">
                            <tbody>
                            <thead>
                            <tr>
                                <th>头像</th>
                                <th>姓名</th>
                                <th>电话</th>
                                <th>会员到期时间</th>
                                <th>金币</th>
                                <th>零钱</th>
                                <th>状态</th>
                                <th>注册平台</th>
                                <th>最后登录平台</th>
                                <th>注册时间</th>
                                <th style="text-align: center">操作</th>
                            </tr>
                            </thead>
                            <tbody id="bodycontent">


                            </tbody>
                        </table>
                    </div><!-- /.box-body -->
                    <div id="pagecontent" class="pagination"></div>
                </div><!-- /.box -->
            </div>
        </div>
    </section>

</#macro>
<#assign maincontent = maincontent in mainLayout />

<#macro mainfooter>
    <!--layoutmain footer...-->
    <!--<br />-->
    <script src="/js/jquery/jquery.form.js"></script>
    <script src="/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="/plugins/datatables/dataTables.bootstrap.min.js"></script>

    <script type="text/javascript">

        var user_data = {
        };
        
        function searchStudents() {


            user_data = {
                state:$('#input_state').val(),
                regapp:$('#input_regstate').val(),
                username:$('#input_nick').val(),
                phone:$('#input_phone').val(),
                isvip:$('#input_isvip').val(),
                btime:'',
                etime:'',
                pno: 1,
                pagesize: 10,
                allcount:-1
            };
            LoadUserList();
        }
        //加载列表
        searchStudents();
        function LoadUserList() {
            $('#pagecontent').html('');
            $.ajax({
                    url: '/api/user/getuserlist',
                    data: user_data,
                    dataType: 'json',
                    success: function (data) {
                        if (mortise_layout.ValidataResult(data)) {
                            if (data.result) {
                                user_data.allcount = data.result.count;
                                var html = '';
                                $.each(data.result.list, function (index, item) {
                                    html += getHtml(item);
                                })
                                $('#bodycontent').html(html);

                                ShowPage('pagecontent', user_data, function (pno) {
                                    user_data.pno = pno;
                                    LoadUserList();
                                });
                            }
                            else {
                                alert('返回数据错误！');
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
        function  getHtml(dataObject) {
            var regAppHtml='';
            if (dataObject.userBaseModel.fState==0){
                regAppHtml= '<span class="label label-success">正常</span>'
            }
            else if (dataObject.userBaseModel.fState=='1'){
                regAppHtml= '<span class="label label-danger">锁定</span>'
            }
            else if (dataObject.userBaseModel.fState=='2'){
                regAppHtml= '<span class="label label-warning">禁言</span>'
            }
            return ' <tr>'+
            '<td><img style="width: 40px;height: 40px;" src="'+dataObject.userBaseModel.fPhoto+'"></td>'+
            '<td>'+dataObject.userBaseModel.fUsername+'</td>'+
                '<td>'+dataObject.userBaseModel.fPhone+'</td>'+
                '<td>'+dataObject.fVipdate+'</td>'+
            '<td>'+dataObject.fCoin+'</td>'+
                '<td>'+dataObject.fMoney+'</td>'+
                '<td>'+regAppHtml+'</td>'+
                '<td>'+GetAppName(dataObject.userBaseModel.fRegapp)+'</td>'+
            '<td>'+GetAppName(dataObject.fLastloginapp)+'</td>'+
            '<td>'+dataObject.userBaseModel.fIntime+'</td>'+
                '<td>' +
                '<a style="cursor: pointer" href="/page/user/userinfo?userid='+dataObject.userBaseModel.fId+'">详情</a>&nbsp;&nbsp;' +
                '<a style="cursor: pointer" href="#" onclick="UpdateSateUser(\''+dataObject.userBaseModel.fId+'\',1)">封号</a>&nbsp;&nbsp;' +
                '<a style="cursor: pointer" href="#" onclick="UpdateSateUser(\''+dataObject.userBaseModel.fId+'\',2)">禁言</a>&nbsp;&nbsp;' +
                '<a style="cursor: pointer" href="#" onclick="UpdateSateUser(\''+dataObject.userBaseModel.fId+'\',0)">恢复</a></td>'+
            '</tr>';
        }
        function UpdateSateUser(uid,state) {
            $.ajax({
                    url: '/api/user/updateuserstate',
                    data: {userid: uid,state:state},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '操作成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                                LoadUserList();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '操作失败！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
    </script>
</#macro>
<#assign mainfooter = mainfooter in mainLayout />
<@mainLayout.page title="用户管理"/>